package _17_剑指Offer;

public class _58_剑指Offer左旋转字符串II {

    public static void main(String[] args) {

        _58_剑指Offer左旋转字符串II v = new _58_剑指Offer左旋转字符串II();

        String str = "abcdefg";
        int k = 2;
        System.out.println(v.reverseLeftWords(str, 2));

    }

    // 直接拼接
    public String reverseLeftWords(String s, int n) {
        StringBuilder sb = new StringBuilder();
        sb.append(s, n, s.length());
        sb.append(s, 0, n);
        return sb.toString();
    }

    // 拼接字符串操作, 遍历拼接
    public String reverseLeftWords2(String s, int n) {
        StringBuilder sb = new StringBuilder();
        int sLen = s.length();
        int len = sLen + n;
        for (int i = n; i < len; i++) {
            int index = i >= sLen? i - sLen: i;
            sb.append(s.charAt(index));
        }
        return sb.toString();
    }


    // 字符串截取拼接
    public String reverseLeftWords1(String s, int n) {
        return s.substring(n) + s.substring(0, n);
    }

}
